package com.hera.base.web.vaadin;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;

import com.hera.base.util.Inject;
import com.hera.base.util.VaadinUtil;
import com.hera.base.util.exception.ManejadorExcepcionMensaje;
import com.vaadin.annotations.Theme;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Component;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;

@SuppressWarnings("serial")
@Theme("admin")
public class AplicationUI extends UI {

	private static final long serialVersionUID = 1L;

	private static Logger log = Logger.getLogger(AplicationUI.class);

	@Autowired
	private MessageSource messageSource;

	Window window;

	@Override
	protected void init(VaadinRequest request) {
		Inject.inject(this);
//		Permiso permiso = (Permiso) VaadinSession.getCurrent().getAttribute("USUARIO");
		Component component=null;
//		if (permiso == null) {
//			component=new PortalLogin();
//		} else {
//			component=new PortalPlantilla();
//		}
		

		//RequestDispatcher requestDispatcher = ((HttpServletRequest)request).getRequestDispatcher("/movil/demo.jsp");
		//requestDispatcher.forward(arg0, arg1);
		
		component=new PortalLogin();
		VaadinUtil.aplicarReflexionId(component);
		setContent(component);
		UI.getCurrent().setErrorHandler(new ManejadorExcepcionMensaje(messageSource, this.getLocale()));

	}

}
